package com.atguigu.test;

import com.atguigu.bean.Boss;
import com.atguigu.bean.Car;
import com.atguigu.bean.Color;
import com.atguigu.config.MainConfigOfAutowired;
import com.atguigu.config.MainConfigOfLifeCycle;
import com.atguigu.dao.BookDao;
import com.atguigu.service.BookService;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ApplicationObjectSupport;


/**
 * @author 张晓
 * @create 2020-11-18 22:54
 */
public class IOCTest_Autowired {
    @Test
    public void test01(){
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfigOfAutowired.class);
        BookService bookService = (BookService) applicationContext.getBean("bookService");
        System.out.println(bookService.toString());

        //BookDao bookDao = applicationContext.getBean(BookDao.class);

        //System.out.println(bookDao);

        Boss boss = applicationContext.getBean(Boss.class);
        System.out.println(boss);
        Car car = applicationContext.getBean(Car.class);
        System.out.println(car);


        Color color = applicationContext.getBean(Color.class);
        System.out.println(applicationContext);
        System.out.println(color);


        //关闭容器
        applicationContext.close();
    }

}
